<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\Attachment;
use app\common\model\Stat;
use fast\Date;
use think\Db;
use think\Request;

/**
 * 控制台
 *
 * @icon   fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Staffdashboard extends Backend
{

    /**
     * Staff模型对象
     * @var \app\admin\model\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\User;

    }


    public function index()
    {
        //全部人员
        $all = $this->model->where(['type'=>1])->count();

        //空闲
        $leisure = $this->model->where(['service_status'=>0,'type'=>1])->count();

        //预约占用
        $sub_occupy = $this->model->where(['service_status'=>1,'type'=>1])->count();

        //其他占用
        $other_occupy = $this->model->where(['service_status'=>2,'type'=>1])->count();

        //待上钟
        $wait_work = $this->model->where(['service_status'=>3,'type'=>1])->count();

        //服务中
        $in_service = $this->model->where(['service_status'=>4,'type'=>1])->count();

        //超时
        $timeout = $this->model->where(['service_status'=>5,'type'=>1])->count();

        //人员列表
        $staff_list =  $this->model->where(['type'=>1])
            ->field('id,nickname,mobile,avatar,service_status,work_end_time')->select();
        $stat_model = new Stat();

        foreach ($staff_list as $k=>$v){
            $staff_list[$k]['num'] = $stat_model->projectNum($v['id']);
        }
        $this->view->assign([
            'all'=>$all,
            'leisure'=>$leisure,
            'sub_occupy'=>$sub_occupy,
            'other_occupy'=>$other_occupy,
            'wait_work'=>$wait_work,
            'in_service'=>$in_service,
            'timeout'=>$timeout,
            'staff_list'=>$staff_list
        ]);

        return $this->view->fetch();

    }

}